package BehaviorModel.observerModel;

/**
 * 功能描述: 观察者模式 - 测试类
 * 2024/02/20
 * <p>
 * ZhangYi
 */
public class Client {
    public static void main(String[] args){
        WeatherData weatherData = new WeatherData();
        // 设置天气数据
        weatherData.setHumidity(100f);
        weatherData.setPressure(10f);
        weatherData.setTemperature(5);
        System.out.println(String.format(" 当前的天气信息为 %s ",weatherData.toString()));
        // 注册到观察者中
        // 1. 新浪
        Sina sina = new Sina();
        weatherData.registerObserver(sina);
        // 2. 气象网
        MeteorologicalNetwork meteorologicalNetwork = new MeteorologicalNetwork();
        weatherData.registerObserver(meteorologicalNetwork);

        //3. 欧洲气象网
        weatherData.registerObserver(new EuropeanMeteorologicalAssociation());

        //4. 世界气象组织
        WorldMeteorologicalOrganization worldMeteorologicalOrganization = new WorldMeteorologicalOrganization();
        weatherData.registerObserver(worldMeteorologicalOrganization);

        // 通知所以的观察者
        weatherData.notifyObservers();
        weatherData.setTemperature(9.0f);

        weatherData.notifyObservers();
        // 移除 新浪 观察者
        weatherData.removeObserver(sina);
        weatherData.removeObserver(worldMeteorologicalOrganization);
        weatherData.setTemperature(1.0f);
        weatherData.notifyObservers();
    }
}
